home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
061-070
/
amok63
/
m2ced
/
txt.lha
/
TimerSupport.mod
< prev
next >
Wrap
Text File
|
1991-11-13
|
5KB
|
190 lines
(**********************************************************************
:Program. TimerSupport.mod
:Contents. support to handle the timer.device
:Author. Hartmut Höhn
:Address. Friedenstraße 1, D 6255 Dornburg 5
:Copyright. Public Domain
:Language. Modula-2
:Translator. M2Amiga A+L V3.2d
:History. V1.0 Harmut Höhn 27.Dec.1988
:History. V1.1 [bne] 18.May.1989 (- MODIV, cosmetics)
:History. V1.2 [bne] 29.May.1989 (bugs fixed, compiler V3.2)
:History. V2.0 [bne] 06.Aug.1989 (+ inline doc, optimized)
:History. V2.1 [bne] 03.Sep.1989 (new Add/Sub/CmpTime)
**********************************************************************)
(*$ StackParms:=FALSE Volatile:=FALSE CaseChk:=FALSE *)
(*$ StackChk:=FALSE RangeChk:=FALSE OverflowChk:=FALSE NilChk:=FALSE *)
IMPLEMENTATION MODULE TimerSupport;
(* Copyright (c) 1988, 1989 by Hartmut Höhn & Nicolas Benezan *)
FROM Arts IMPORT Assert;
FROM ExecD IMPORT invalid, MsgPortPtr,DevicePtr;
FROM ExecL IMPORT CloseDevice, DoIO, OpenDevice;
FROM ExecSupport IMPORT CreateExtIO, CreatePort, DeleteExtIO, DeletePort;
FROM SYSTEM IMPORT ADR, LONGSET;
FROM Timer IMPORT addRequest, getSysTime, IOTimer, IOTimerPtr,
setSysTime, timerName, TimeVal;
IMPORT Timer;
VAR
timerBase : DevicePtr;
timerReqPtr: IOTimerPtr;
open : INTEGER;
CONST
micPerSec = 1000000;
secsPerMin = 60;
minsPerHour = 60;
hoursPerDay = 24;
daysPerYear = 365;
daysPerLeap = 4*daysPerYear+1;
notOpen = "timer.device not open";
PROCEDURE CloseTimer;
BEGIN
DEC(open);
IF open=0 THEN
CloseDevice(timerReqPtr);
DeleteExtIO(timerReqPtr);
DeletePort(timerPort);
END;
END CloseTimer;
PROCEDURE OpenTimer(Mode: TimerMode): BOOLEAN;
BEGIN
IF open=0 THEN
timerPort:=CreatePort(NIL, 0);
IF timerPort#NIL THEN
timerReqPtr:=CreateExtIO(timerPort, SIZE(IOTimer));
IF timerReqPtr#NIL THEN
OpenDevice(ADR(timerName), ORD(Mode), timerReqPtr, LONGSET{});
IF timerReqPtr^.node.error=0 THEN
INC(open);
timerBase:=timerReqPtr^.node.device;
RETURN TRUE;
END;
DeleteExtIO(timerReqPtr);
END;
DeletePort(timerPort);
END;
RETURN FALSE
END;
INC(open);
RETURN TRUE
END OpenTimer;
PROCEDURE TimerWait(Time: TimeVal);
BEGIN
Assert(open>0, ADR(notOpen));
WITH timerReqPtr^ DO
node.command:=addRequest;
time:=Time;
END;
DoIO(timerReqPtr);
END TimerWait;
PROCEDURE GetSysTime(VAR Time: TimeVal);
BEGIN
Assert(open>0, ADR(notOpen));
timerReqPtr^.node.command:=getSysTime;
DoIO(timerReqPtr);
Time:=timerReqPtr^.time
END GetSysTime;
PROCEDURE SetSysTime(Time: TimeVal);
BEGIN
Assert(open>0, ADR(notOpen));
WITH timerReqPtr^ DO
node.command:=setSysTime;
time:=Time;
END;
DoIO(timerReqPtr);
END SetSysTime;
PROCEDURE SysToNormalTime( SysTime: TimeVal;
VAR Year, Month, Day: LONGINT;
VAR Hour, Minute, Second: LONGINT);
BEGIN
Second:=SysTime.secs;
Minute:=Second DIV secsPerMin;
Second:=Second MOD secsPerMin;
Hour:=Minute DIV minsPerHour;
Minute:=Minute MOD minsPerHour;
Day:=Hour DIV hoursPerDay;
Hour:=Hour MOD hoursPerDay;
DEC(Day, 790); (* offset 1.Jan.78 to 1.Mar.1980 *)
Year:=(4*Day+3) DIV daysPerLeap;
DEC(Day, daysPerLeap*Year DIV 4);
Month:=(5*Day+2) DIV 153; (* 0=Mar ... 11=Feb next year *)
DEC(Day,(153*Month+2) DIV 5);
INC(Day);
INC(Month, 3); (* Mar=3 ... next Feb=14 *)
IF Month>12 THEN
INC(Year);
DEC(Month, 12);
END;
INC(Year, 1980);
END SysToNormalTime;
PROCEDURE NormalToSysTime( Year, Month, Day: LONGINT;
Hour, Minute, Second: LONGINT;
VAR SysTime: TimeVal);
BEGIN
DEC(Year, 1980);
DEC(Month, 3); (* 0=Mar ... 11=Feb next year *)
IF Month<0 THEN
INC(Month, 12);
DEC(Year);
END;
DEC(Day);
INC(Day, (153*Month+2) DIV 5);
INC(Day, daysPerLeap*Year DIV 4);
INC(Day, 790);
INC(Hour, Day*hoursPerDay);
INC(Minute, Hour*minsPerHour);
INC(Second, Minute*secsPerMin);
WITH SysTime DO
secs:=Second;
micro:=0;
END;
END NormalToSysTime;
PROCEDURE NewTimerRequest(RequestPtr: IOTimerPtr);
BEGIN
Assert(open>0, ADR(notOpen));
RequestPtr^:=timerReqPtr^;
WITH RequestPtr^.node DO
command:=invalid;
error:=0;
END;
END NewTimerRequest;
PROCEDURE AddTime(VAR dest: TimeVal;
source: TimeVal);
BEGIN
Assert(open>0, ADR(notOpen));
Timer.AddTime(timerBase, ADR(dest), ADR(source));
END AddTime;
PROCEDURE SubTime(VAR dest: TimeVal;
source: TimeVal);
BEGIN
Assert(open>0, ADR(notOpen));
Timer.SubTime(timerBase, ADR(dest), ADR(source));
END SubTime;
PROCEDURE CmpTime(time1, time2: TimeVal): INTEGER;
BEGIN
Assert(open>0, ADR(notOpen));
RETURN Timer.CmpTime(timerBase, ADR(time1), ADR(time2));
END CmpTime;
BEGIN
open:=0;
CLOSE
CloseTimer;
END TimerSupport.